package com.cnt.controller;

import com.cnt.entity.Donations;
import com.cnt.entity.RequestMoney;
import com.cnt.service.DonationRequestService;
import com.cnt.service.DonationsService;
import com.cnt.service.RequestMoneyService;
import com.cnt.vo.CheckDonationsVo;
import com.cnt.vo.RequestMoneyVo;
import com.cnt.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/donations")
public class DonationsController {
    @Autowired
    private DonationsService donationsService;
    @Autowired
    private DonationRequestService donationRequestService;
    @Autowired
    private RequestMoneyService requestMoneyService;

    @PostMapping("/agree")
    public ResultVo<String> agreeRequest(@RequestParam Integer requestId){
        return donationRequestService.agreeRequest(requestId);
    }

    @PostMapping("/agreeAndChangeAmount")
    public ResultVo<String> agreeRequestAndChangeAmount(@RequestParam Integer requestId, @RequestParam double changeAmount){
        return donationRequestService.agreeRequestAndChangeAmount(requestId, changeAmount);
    }

    @PostMapping("/agreeList")
    public ResultVo<String> agreeRequestList(@RequestBody List<Integer> list){
        return donationRequestService.agreeRequestList(list);
    }

    @PostMapping("/reject")
    public ResultVo<String> rejectRequest(@RequestParam Integer requestId){
        return donationRequestService.rejectRequest(requestId);
    }

    @PostMapping("/rejectList")
    public ResultVo<String> rejectRequestList(@RequestBody List<Integer> list){

        return donationRequestService.rejectRequestList(list);
    }

    @PostMapping("/agreeRequestMoney")
    public ResultVo<String> agreeRequestMoney(@RequestBody RequestMoney requestMoney){
        return requestMoneyService.agreeRequestMoney(requestMoney.getRequestMoneyId(), requestMoney.getEvaluate());
    }

    @PostMapping("/rejectRequestMoney")
    public ResultVo<String> rejectRequestMoney(@RequestBody RequestMoney requestMoney){
        return requestMoneyService.rejectRequestMoney(requestMoney.getRequestMoneyId(), requestMoney.getEvaluate());
    }
    @GetMapping("/checkList")
    public ResultVo<List<CheckDonationsVo>> getCheckList(@RequestParam(name = "minAmount", required = false) Double minAmount,
                                                         @RequestParam(name = "maxAmount", required = false) Double maxAmount,
                                                         @RequestParam(name = "name", required = false) String name) {
        // 调用 donationService 的方法获取募捐单列表
        List<CheckDonationsVo> checkList = donationRequestService.getCheckList(minAmount, maxAmount, name);
        return new ResultVo<>(0, "查询成功", checkList);
    }

    @PostMapping("/changeStatus")
    public ResultVo<Void> changeStatus(@RequestParam(name = "donationsId") Integer donationsId) {
        // 调用服务层方法进行状态修改逻辑处理
        return donationsService.changeStatus(donationsId);
    }

    @PostMapping("/declareEnd")
    public ResultVo<Void> declareEnd(@RequestParam(name = "donationsId") Integer donationsId) {
        return donationsService.declareEnd(donationsId);
    }

    @GetMapping("/getRequestMoneyVo")
    public ResultVo<List<RequestMoneyVo>> getRequestMoneyVo(){
        return requestMoneyService.getRequestMoneyVo();
    }

    @PostMapping("/agreeAndGrant")
    public ResultVo<String> grant(@RequestParam Integer requestMoneyId){
        return requestMoneyService.grant(requestMoneyId);
    }

    @GetMapping("/List")
    public ResultVo<List<Donations>> getList(@RequestParam(name = "min", required = false) Double min,
                                                         @RequestParam(name = "max", required = false) Double max,
                                                         @RequestParam(name = "name", required = false) String name) {
        // 调用 donationService 的方法获取募捐单列表
        return  donationsService.List(min, max, name);
    }

}
